//
//  ConfigViewController.m
//  inquiry
//
//  Created by 高宇 on 2020/7/26.
//  Copyright © 2020 高宇. All rights reserved.
//

#import "ConfigViewController.h"
#import "LoginViewController.h"

@interface ConfigViewController ()

@end

@implementation ConfigViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.title = @"设置";
    
    UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
    backButton.frame = CGRectMake(0, 0, 40, 30);
    [backButton setTitle:@" 返回" forState:UIControlStateNormal];
    [backButton setTitleColor:[UIColor colorWithRed:173/255.0 green:173/255.0 blue:189/255.0 alpha:1.0] forState:0];
    [backButton setImage:[[UIImage imageNamed:@"fanhui"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];

    [backButton addTarget:self action:@selector(backClick:) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
}

- (IBAction)tuiChu:(id)sender {
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"是否退出登录" message: nil preferredStyle:UIAlertControllerStyleAlert];
    [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
        
    }]];
    [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        // 删除NSUserDefaults所有记录
        NSString *appDomain = [[NSBundle mainBundle] bundleIdentifier];
        NSUserDefaults * defautls = [NSUserDefaults standardUserDefaults];
        [defautls removePersistentDomainForName:appDomain];
        
        //退出登录
        [self dismissViewControllerAnimated:NO completion:^{
            LoginViewController *vc = [[LoginViewController alloc] init];
            UIWindow *window = [UIApplication sharedApplication].keyWindow;
            window.rootViewController = vc;
            [[UIApplication sharedApplication].keyWindow makeKeyAndVisible];
        }];
    }]];
    [self presentViewController:alert animated:YES completion:nil];
    
}

//重写返回按钮
- (void)backClick:(id)sender {
    [self.navigationController popViewControllerAnimated:YES];
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
